//
//  UIView+HDToolView.m
//  app
//
//  Created by D on 15/5/25.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDToolView.h"


static const CGFloat kMargin = 24.0f;
static const CGFloat kPictureH = 48.0f;
static const CGFloat kPictureW = 52.0f;
static const CGFloat kMessageContentW = 440.0f;
static const CGFloat kMessageContentH =60.0f;

@implementation HDToolView

-(id)initAndFrame:(CGRect)frame
{
    if (self = [super init]) {
        
        self.frame = frame;
        self.backgroundColor = [UIColor whiteColor];
//        self.layer.borderWidth = 0.2;
//        self.layer.borderColor = [UIColor grayColor].CGColor;
        
        
        
        self.mainView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        self.mainView.image = [UIImage imageNamed:@"bg_toolBar_PubInput"];
//       [self addSubview:self.mainView];
        
        self.emjio = [[HDReplyToolButton alloc]initWithFrame:CGRectOf([self.ubo  ox:kMargin/2 fy:UB_1_2 oy:-kPictureH/4], [self.ubo ow:kPictureH/2 oh:kPictureH/2])];
        self.emjio.tag = 0;
        self.emjio.isEmoji = YES;
        [self.emjio setBackgroundImage:[UIImage imageNamed:@"btn_publish_openEmoji"] forState:UIControlStateNormal];
        [self.emjio addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.emjio];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeImage:) name:@"changeimage" object:nil];
        
        self.camera = [[HDReplyToolButton alloc]initWithFrame:CGRectOf([self.emjio.ufo fx:1 ox:kMargin/2 fy:UB_1_2 oy:-kPictureH/4], [self.ubo ow:kPictureW/2 oh:kPictureH/2])];
        self.camera.tag = 1;
        [self.camera setBackgroundImage:[UIImage imageNamed:@"btn_publish_openCamera"] forState:UIControlStateNormal];
        [self.camera addTarget:self  action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.camera];
        
        CGFloat contentW = UBO_WINDOW.width - 4*kMargin/2 - 2*kPictureH/2;
        
        self.messageContent = [[UITextView alloc]initWithFrame:CGRectOf([self.camera.ufo fx:1 ox:kMargin/2 fy:UB_1_2 oy:-kMessageContentH/4], [self.ubo ow:contentW oh:kMessageContentH/2])];
//        [self.messageContent setBorderStyle:UITextBorderStyleRoundedRect];
        self.messageContent.font = JKAppGlobleFontMenu;
        [self.messageContent setReturnKeyType:UIReturnKeySend];
        self.messageContent.layer.borderWidth = 0.5;
        self.messageContent.layer.borderColor = [UIColor grayColor].CGColor;
        self.messageContent.layer.masksToBounds = YES;
        self.messageContent.layer.cornerRadius = UF(10);
        [self addSubview:self.messageContent];
        
        self.sendMessage = [[HDReplyToolButton alloc]initWithFrame:CGRectOf([self.ubo fx:1 ux:-kPictureW-kMargin fy:UB_1_2 uy:-kPictureH/2], [self.ubo uw:kPictureH uh:kPictureW])];
        self.sendMessage.tag = 2;
        [self.sendMessage setBackgroundImage:[UIImage imageNamed:@"btn_public"] forState:UIControlStateNormal];
        [self.sendMessage addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:self.sendMessage];
        
        
    }
    
    return self;
}

-(void)drawRect:(CGRect)rect
{
    [self setBackgroundColor:[UIColor clearColor]];
    [self drawSeperatorLineLeft:UF(0) right:UF(0)];
    [self drawHorizonLineLeft:UF(0) right:UF(0) at:UP(0.5)];
}

-(void)clickButton:(UIButton*)sender
{
    if (self.delegate &&  [self.delegate respondsToSelector:@selector(clickMianViewButtons:)]) {
        [self.delegate clickMianViewButtons:sender];
    }
}
-(void)changeImage:(NSNotification*)info
{
    NSDictionary *pmidDictionary = [info object];
    if ([[pmidDictionary objectForKey:@"sign"]integerValue] == 0 ) {
        [self.emjio setBackgroundImage:[UIImage imageNamed:@"btn_publish_openEmoji"] forState:UIControlStateNormal];
    }else
    {
        [self.emjio setBackgroundImage:[UIImage imageNamed:@"btn_publish_openKeyBoard"] forState:UIControlStateNormal];
    }
    
}
@end
